package com.ricky.handler.authorise;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import com.ricky.core.net.abs.Request;
import com.ricky.core.net.msg.Context;
import com.ricky.core.net.utils.Attributes;
import com.ricky.game.GameWorld;
import com.ricky.game.Hero;
import com.ricky.game.MsgHelper;
import com.ricky.handler.IHandler;
import com.ricky.handler.action.Pub;

public class RoomAu implements IHandler{

	@SuppressWarnings("rawtypes")
	@Override
	public void proccess(Request request,Map<String,Object> context) {
		@SuppressWarnings("unchecked")
		Map<String,Object> msg =context;
//		Hero h = (Hero) request.getAttribute(Attributes.HERO);
//		if(h!=null)
//		{
//			int type = (Integer) msg.get("t");
//			
//		}else
		{
//			String heroName = (String)msg.get("heroName");
			String userName = (String) request.getAttribute(Attributes.USER_Name); //msg.get("name").toString();//用户名
			Hero hero = new Hero();
			hero.setName(userName);
			hero.setUserName(userName);
			
			Map<String,Object> arg=(Map<String, Object>) msg.get("arg");
			for(Map.Entry<String, Object>  entry: arg.entrySet())
			{
				if(entry.getValue()!=null)
					hero.setAttribute(entry.getKey(), entry.getValue());
			}
			
			GameWorld.getInstance().joinWorld(hero, request);
			request.setAttribute(Attributes.HERO, hero);
			request.isValidate(true);
			
			Map<String,Object> smsg=new HashMap<String,Object>();
			smsg.put("cmd","validated");
			smsg.put("arg",true);
			MsgHelper.sendMsg(request, smsg);
		}
	}

}
